<template>
  <div class="border-line card">
    <header-title title="" @fullScreen="handleFullScreen"></header-title>
    <div class="subtext">{{ `房屋租金价格（平均租金价格：${pjjgt}元/套，${pjjgm}元/每平米）` }}</div>
    <div class="subtext" style="margin-left: 1%; width: 49%">{{ `申请情况分析（全市总申请人数：${sqrs}人）` }}</div>
    <div class="content">
      <div class="column">
        <div class="table">
          <div class="header">
            <div class="col">房屋名称</div>
            <div class="col">房屋均价(元/套)</div>
            <div class="col">房屋单价(元/㎡)</div>
          </div>
          <vue-seamless-scroll :data="listData" :class-option="classOption" class="scroll-warp">
            <ul class="item">
              <li v-for="(item, index) in listData" :key="index">
                <span class="col">
                  <ellipsis :length="20">{{ item.name }}</ellipsis>
                </span>
                <span class="col">{{ item.value }}</span>
                <span class="col">{{ item.FWCOUNT }}</span>
              </li>
            </ul>
          </vue-seamless-scroll>
        </div>
      </div>
      <div class="column">
        <div @mouseenter="clearAutoPlay" @mouseleave="setAutoPlay">
          <echarts-view ref="echarts2" :options="option" height="300px"></echarts-view>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import headerTitle from './headerTitle.vue'
import { echartsView, Ellipsis } from '@/components'
import vueSeamlessScroll from 'vue-seamless-scroll'
import axios from 'axios'
import * as echarts from 'echarts'
export default {
  name: 'Right2',
  props: {
    areaID: {
      type: String,
      default: '',
    },
  },
  components: {
    headerTitle,
    echartsView,
    vueSeamlessScroll,
    Ellipsis,
  },
  data() {
    return {
      classOption: {
        singleHeight: 40,
      },
      autoPlayer: null,
      listData: [],
      pjjgt: 0,
      pjjgm: 0,
      sqrs: 0,
      option: {},
    }
  },
  mounted() {
    this.fetchData()
  },
  watch: {
    areaID: function () {
      this.fetchData()
    },
  },
  methods: {
    fetchData() {
      const echart1 = axios({
        method: 'get',
        timeout: 180000,
        url: process.env.VUE_APP_API_BASE_URL_BZF + '/api/Statistics/TJFY_FWZJJG',
        params: {
          Userid: 1,
          QY: this.areaID,
          TJ: 'TJ',
        },
      })
      const echart2 = axios({
        method: 'get',
        timeout: 180000,
        url: process.env.VUE_APP_API_BASE_URL_BZF + '/api/Statistics/TJFY_QBSQQK',
        params: {
          Userid: 1,
          QY: this.areaID,
          TJ: 'TJ',
        },
      })
      Promise.all([echart1, echart2]).then((res) => {
        const xAxisData = []
        const sqrs = []
        const shrs = []
        const tcrs = []
        this.listData = res[0].data.TJinfo
        console.log('this.listData2', this.listData)
        this.pjjgt = res[0].data.num
        this.pjjgm = res[0].data.num1
        res[1].data.TJinfo.forEach((item) => {
          xAxisData.push(item.name)
          sqrs.push(Number(item.value))
          shrs.push(Number(item.namemc))
          tcrs.push(Number(item.FWCOUNT))
        })
        this.sqrs = res[1].data.num
        this.option = {
          tooltip: {
            trigger: 'axis',
            confine: true,
          },
          grid: {
            left: 30,
            right: 0,
            top: 40,
            bottom: '3%',
            containLabel: true,
          },
          dataZoom: [
            // 滑动条
            {
              show: false, // 是否显示滑动条
              type: 'slider', // 这个 dataZoom 组件是 slider 型 dataZoom 组件
              startValue: 0, // 从头开始。
              endValue: 5, // 一次性展示几个。
            },
          ],
          xAxis: {
            data: xAxisData,
            axisLine: {
              show: true,
              lineStyle: {
                color: '#4d565e',
              },
            },
            axisTick: {
              show: false,
            },
          },
          yAxis: [
            {
              type: 'value',
              axisLine: {
                show: false,
                lineStyle: {
                  color: '#EDEDED',
                },
              },
              splitLine: {
                show: false,
                lineStyle: {
                  color: '#1c2538',
                  type: 'dashed',
                },
              },
            },
          ],
          series: [
            {
              name: '申请人数',
              type: 'bar',
              barGap: '50%',
              barWidth: 16,
              data: sqrs,
              itemStyle: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                  { offset: 0, color: '#1b65f1' },
                  { offset: 0.7, color: '#1b65f1' },
                  { offset: 1, color: '#ffffff00' },
                ]),
              },
            },
            {
              z: 10,
              name: '申请人数',
              type: 'pictorialBar',
              symbolPosition: 'end',
              data: sqrs,
              symbol: 'diamond',
              symbolOffset: [-24, '-60%'],
              symbolSize: [16, 10],
              itemStyle: {
                normal: {
                  borderWidth: 2,
                  color: '#4b89ff',
                },
              },
              tooltip: {
                show: false,
              },
            },
            {
              name: '审核人数',
              type: 'bar',
              barGap: '50%',
              barWidth: 16,
              data: shrs,
              itemStyle: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                  { offset: 0, color: '#6c66f7' },
                  { offset: 0.7, color: '#6c66f7' },
                  { offset: 1, color: '#ffffff00' },
                ]),
              },
            },
            {
              z: 10,
              name: '审核人数',
              type: 'pictorialBar',
              symbolPosition: 'end',
              data: shrs,
              symbol: 'diamond',
              symbolOffset: [0, '-60%'],
              symbolSize: [16, 10],
              itemStyle: {
                normal: {
                  borderWidth: 2,
                  color: '#938dff',
                },
              },
              tooltip: {
                show: false,
              },
            },
            {
              name: '退出人数',
              type: 'bar',
              barGap: '50%',
              barWidth: 16,
              data: tcrs,
              itemStyle: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                  { offset: 0, color: '#15f5fe' },
                  { offset: 0.7, color: '#15f5fe' },
                  { offset: 1, color: '#ffffff00' },
                ]),
              },
            },
            {
              z: 10,
              name: '退出人数',
              type: 'pictorialBar',
              symbolPosition: 'end',
              data: tcrs,
              symbol: 'diamond',
              symbolOffset: [24, '-60%'],
              symbolSize: [16, 10],
              itemStyle: {
                normal: {
                  borderWidth: 2,
                  color: '#5df6fc',
                },
              },
              tooltip: {
                show: false,
              },
            },
          ],
        }
        this.$nextTick(() => {
          this.setAutoPlay()
        })
      })
    },
    setAutoPlay() {
      this.clearAutoPlay('setAutoPlay')
      this.autoPlayer = setInterval(() => {
        if (this.option.dataZoom[0].endValue === this.option.series[0].data.length) {
          this.option.dataZoom[0].endValue = 5
          this.option.dataZoom[0].startValue = 0
        } else {
          this.option.dataZoom[0].endValue = this.option.dataZoom[0].endValue + 1
          this.option.dataZoom[0].startValue = this.option.dataZoom[0].startValue + 1
        }
      }, 3000)
    },
    clearAutoPlay() {
      if (!this.$isEmpty(this.autoPlayer)) {
        clearInterval(this.autoPlayer)
      }
    },
    handleFullScreen() {
      this.$emit('fullScreen')
    },
  },
}
</script>
<style lang="less" scoped>
.card {
  height: 400px;
  font-size: 18px;
  .content {
    display: flex;
    flex-direction: row;
    .column {
      flex: 1;
      .table {
        .col {
          flex: 1;
          font-size: 20px;
        }

        .header {
          background: #0f3560;
          font-size: 16px;
          padding: 0 18px;
          color: #fff;
          display: flex;
          justify-content: space-between;
          height: 40px;
          line-height: 40px;
        }

        .scroll-warp {
          height: 248px;
          width: 100%;
          margin: 0 auto;
          overflow: hidden;
          ul {
            list-style: none;
            padding: 0;
            margin: 0 auto;
            li {
              height: 40px;
              line-height: 40px;
              padding: 0 18px;
              color: #61a8ff;
              position: relative;
              font-size: 14px;
              display: flex;
              justify-content: space-between;
              &:nth-child(2n) {
                background: rgb(8, 38, 91);
              }
            }
          }
        }
      }
    }
  }
}
.subtext {
  color: #fff;
  background-color: #0d5b78;
  display: inline-block;
  width: 50%;
  font-size: 20px;
  box-sizing: border-box;
  padding: 5px 10px;
  margin: 6px 0;
}
</style>
